package com.framework.controller;

import com.framework.entity.ter.TerGoods;
import com.framework.exception.util.RespResult;
import com.framework.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 商品控制器
 *
 * @author ck
 * @date 2018/9/17 14:54
 */
@RestController
@Api(value="机具物料模块",tags={"机具物料模块"})
@RequestMapping(value = "goods")
public class GoodsController {

	@Autowired
	private GoodsService goodsService;

	/**
	 * 机具物料列表
	 * @param token 当前人登录的toke
	 * @param name  物料名称
	 * @return
	 */
	@GetMapping("user/queryGoodsList")
	@ApiOperation("机具物料列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="name",value="商品名称",dataType="string", paramType = "query" ),
			@ApiImplicitParam(name="goodsType",value="商品类型 0：全部  1：机具  2：物料",dataType="Integer", paramType = "query",required = true),
	})
	public RespResult queryGoodsList(String token, String name,Integer goodsType) {
		List<TerGoods> list = goodsService.queryGoodsList(token,name,goodsType);
		return RespResult.ok().put("goodsList",list);
	}

	/**
	 * 根据id查询机具物料详情
	 * @param token 当前人登录的token
	 * @param goodsId 机具物料id
	 * @return
	 */
	@GetMapping("user/queryGoodsInfo")
	@ApiOperation("根据id查询机具物料详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="goodsId",value="商品Id",dataType="Long", paramType = "query" ,required = true),
	})
	public RespResult queryGoodsInfo(String token, Long goodsId) {
		Map<String,Object> map = goodsService.queryGoodsInfo(token,goodsId);
		return RespResult.ok(map);
	}

	/**
	 * 根据id查询礼包详情
	 * @param token 当前人登录的token
	 * @param goodsId 机具物料id
	 * @return
	 */
	@GetMapping("user/queryGoodsPresentInfo")
	@ApiOperation("根据id查询过往购买的礼包详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="用户登陆产生的token",dataType="String", paramType = "query" ,required = true),
			@ApiImplicitParam(name="goodsId",value="商品Id",dataType="Long", paramType = "query" ,required = true),
	})
	public RespResult queryGoodsPresentInfo(String token, Long goodsId) {
		Map<String,Object> map = goodsService.queryGoodsPresentInfo(token,goodsId);
		return RespResult.ok(map);
	}



}
